package com.tjetc.adminmanage;

import com.tjetc.domian.Communitycomplaint;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.ComplaintService;
import com.tjetc.vo.Result;
import java.util.List;
import java.util.Scanner;

public class ComplaintManageView {
    private Scanner scanner = new Scanner(System.in);
    private ComplaintService complaintService = ClientProxy.getProxyInstance(ComplaintService.class);

    public void start() {
        while (true) {
            System.out.println("投诉管理菜单");
            System.out.println("1.查询投诉信息");
            System.out.println("2.修改投诉信息");
            System.out.println("0.返回上一级");
            int i = scanner.nextInt();
            switch (i) {
                case 1:
                    System.out.println("查询投诉信息");
                    select();
                    break;
                case 2:
                    update();
                    break;
                case 0:
                    return;
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }
    }

    private void update() {
        System.out.println("修改投诉信息");
        System.out.println("输入要修改的投诉id");
        int complaintid = scanner.nextInt();
        System.out.println("输入要修改的投诉状态('待处理'、'处理中'、'已完成')");
        String status = scanner.next();
        Result result = complaintService.update(complaintid, status);
        System.out.println(result.getMsg());

    }

    private void select() {
        List<Communitycomplaint> list = complaintService.selectAll();
        if (list == null){
            System.out.println("没有数据");
        }else {
            for (Communitycomplaint communitycomplaint : list) {
                System.out.println("id"+communitycomplaint.getComplaintid()+" residentid"+communitycomplaint.getResidentid()+" complaintdate"+communitycomplaint.getComplaintdate()+" complainttime"+communitycomplaint.getComplainttime()+" description"+communitycomplaint.getDescription()+" status"+ communitycomplaint.getStatus()+" name:"+communitycomplaint.getResident().getName());
            }
        }
    }
}
